layui.use(['layer', 'element', 'admin', 'form', 'formX', 'upload'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var element = layui.element;
    var admin = layui.admin;
    var form = layui.form;
    var formX = layui.formX;
    var upload = layui.upload;

    /* 选择头像 */
    $('#userInfoHead').click(function () {
        admin.cropImg({
            imgSrc: $('#userInfoHead>img').attr('src'),
            onCrop: function (res) {
                $('#userInfoHead>img').attr('src', res);
                admin.req(prefix + "/updateAvatar",
                    {avatarBase64: res},
                    function (resp) {
                        himio.notice.resp(resp, function () {
                            parent.layui.jquery('.layui-layout-admin>.layui-header .layui-nav img.layui-nav-img').attr('src', res);
                        });
                    }, "post");
            }
        });
    });

    /* 监听表单提交 */
    form.on('submit(userInfoSubmit)', function (data) {
        admin.req(prefix + "/update", data.field, function (resp) {
            himio.notice.resp(resp, function () {
                location.reload();
            }, false);
        }, "post")
        return false;
    });

    form.on('submit(resetPwdSubmit)', function (data) {
        if (checkPwd(charType, data.field.newPassword)) {
            admin.req(prefix + "/resetPwd", data.field, function (resp) {
                himio.notice.resp(resp, function () {
                    location.reload();
                });
            }, "post")
        }
        return false;
    });


});
